﻿//========================================================= 
/**@file KeyboardMirror.h
 * @brief 模拟键盘操作
 * 
 * @date 2018-08-27   15:00:39
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_KEYBOARDMIRROR_H_
#define _LIBZHOUYB_KEYBOARDMIRROR_H_
//--------------------------------------------------------- 
#include "../../../include/Base.h"
//--------------------------------------------------------- 
namespace zhou_yb {
namespace extension {
namespace ability {
//--------------------------------------------------------- 
/**
 * @brief 模拟键盘按键
 * @date 2018-08-27 14:04
 */
class KeyboardMirror
{
protected:
    KeyboardMirror() {}
public:
    /// 按下按键
    static inline void press_down(byte vk)
    {
        keybd_event(vk, 0, 0, NULL);
    }
    /// 抬起按键
    static inline void press_up(byte vk)
    {
        keybd_event(vk, 0, KEYEVENTF_KEYUP, NULL);
    }
    /// 模拟一次按键操作
    static void press(byte vk)
    {
        press_down(vk);
        press_up(vk);
    }
    /// 模拟打字
    static void typing(char c)
    {
        bool isShift = false;
        byte bVK = c;
        switch(c)
        {
        case ':':
            isShift = true;
        case ';':
            bVK = VK_OEM_1;
            break;
        case '?':
            isShift = true;
        case '/':
            bVK = VK_OEM_2;
            break;
        case '~':
            isShift = true;
        case '`':
            bVK = VK_OEM_3;
            break;
        case '{':
            isShift = true;
        case '[':
            bVK = VK_OEM_4;
            break;
        case '|':
            isShift = true;
        case '\\':
            bVK = VK_OEM_5;
            break;
        case '}':
            isShift = true;
        case ']':
            bVK = VK_OEM_6;
            break;
        case '\"':
            isShift = true;
        case '\'':
            bVK = VK_OEM_7;
            break;
        case '+':
            bVK = VK_OEM_PLUS;
            break;
        case ',':
            bVK = VK_OEM_COMMA;
            break;
        case '-':
            bVK = VK_OEM_MINUS;
            break;
        case '.':
            bVK = VK_OEM_PERIOD;
            break;
        default:
            break;
        }
        if(isShift) press_down(VK_SHIFT);
        press(bVK);
        if(isShift) press_up(VK_SHIFT);
    }
};
//--------------------------------------------------------- 
} // namespace ability 
} // namespace extension 
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_KEYBOARDMIRROR_H_
//========================================================= 